﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;

using LEEAAttendanceControl.Web;
using LEEAAttendanceControl.Web.Services;
using System.ServiceModel.DomainServices.Client;

namespace LEEAAttendanceControl.Views
{
    public partial class SpecificCompany : Page
    {
        LEEAContext context = new LEEAContext();

        Company company = new Company();

        public SpecificCompany()
        {
            InitializeComponent();

            Title = ((App)Application.Current).DisplayName + ": Company Details";
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            App myApp = (App)Application.Current;

            myApp.ClearEvents();

            CompanyBlock.Text = myApp.DisplayName + ": Company Details";

            context.Load(context.GetCompanyByIdQuery(myApp.CompanyID.Value), OnCompanyLoadCompleted, null);
        }

        private void OnCompanyLoadCompleted(LoadOperation load)
        {
            company = load.Entities.FirstOrDefault() as Company;

            if (company != null)
            {
                DataContext = company;
            }
        }
    }
}
